﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using IRIS.Models;
namespace IRIS.Controllers
{
    public class LinkCategoryController : Controller
    {
        //
        // GET: /LinkCategory/

        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /LinkCategory/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /LinkCategory/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /LinkCategory/Create

        [HttpPost]
        public ActionResult Create(LinkCategory linkCategory)
        {
            //validate input
            if(string.IsNullOrEmpty(linkCategory.Description))
                ModelState.AddModelError("Description","Það verður að fylla út þennan reit");
            if (string.IsNullOrEmpty(linkCategory.Name))
                ModelState.AddModelError("Name", "Það verður að fylla út þennan reit");
            try
            {
                if (ModelState.IsValid)
                {
                    //insert into db
                    return RedirectToAction("Index");
                }
                else
                {
                    return View(linkCategory);    
                }
            }
            catch
            {
                //else give error to user
                return View(linkCategory);
            }
        }
        
        //
        // GET: /LinkCategory/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /LinkCategory/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, LinkCategory linkCategory)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /LinkCategory/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /LinkCategory/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
